﻿<%@ Page Language="C#" MasterPageFile="~/ExampleMaster.Master" AutoEventWireup="true"
    CodeBehind="SimpleOrderBy.aspx.cs" Inherits="Web.Samples.SimpleOrderBy" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleZone" runat="server">
    Simple Orderby
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="IntroTextZone" runat="server">
    Using LINQ you could easily order all objects in a collection. Below are examples
    of taking a basic collection and ordering it by a property in descending and ascending
    order.
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="QueryExpressZone" runat="server">
    <pre class="code">            <span style="color: rgb(0,0,255)">var</span> query = <span
        style="color: rgb(0,0,255)">from</span> p <span style="color: rgb(0,0,255)">in</span> <span
            style="color: rgb(43,145,175)">Product</span>.GetProducts()
                        <span style="color: rgb(0,0,255)">orderby</span> p.Name
                        <span style="color: rgb(0,0,255)">select</span> p;

            <span style="color: rgb(0,0,255)">this</span>.litQueryResult.Text = <span style="color: rgb(163,21,21)">"&lt;strong&gt;Ascending Order&lt;/strong&gt;&lt;br /&gt;\n"</span>;
            <span style="color: rgb(0,0,255)">foreach</span> (<span style="color: rgb(43,145,175)">Product</span> p <span
                style="color: rgb(0,0,255)">in</span> query.Take(10))
                <span style="color: rgb(0,0,255)">this</span>.litQueryResult.Text += p.Name + <span
                    style="color: rgb(163,21,21)">"&lt;br /&gt;\n"</span>;

            <span style="color: rgb(0,0,255)">this</span>.litQueryResult.Text += <span style="color: rgb(163,21,21)">"&lt;br /&gt;\n"</span>;

            query = <span style="color: rgb(0,0,255)">from</span> p <span style="color: rgb(0,0,255)">in</span> <span
                style="color: rgb(43,145,175)">Product</span>.GetProducts()
                    <span style="color: rgb(0,0,255)">orderby</span> p.Name <span style="color: rgb(0,0,255)">descending
                    </span>                    <span style="color: rgb(0,0,255)">select</span> p;

            <span style="color: rgb(0,0,255)">this</span>.litQueryResult.Text += <span style="color: rgb(163,21,21)">"&lt;strong&gt;Descending Order&lt;/strong&gt;&lt;br /&gt;\n"</span>;
            <span style="color: rgb(0,0,255)">foreach</span> (<span style="color: rgb(43,145,175)">Product</span> p <span
                style="color: rgb(0,0,255)">in</span> query.Take(10))
                <span style="color: rgb(0,0,255)">this</span>.litQueryResult.Text += p.Name + <span
                    style="color: rgb(163,21,21)">"&lt;br /&gt;\n"</span>;</pre>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="QueryResultsZone" runat="server">
    <asp:Literal ID="litQueryResult" runat="server" />
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ImperativeZone" runat="server">
    <pre class="code">            <span style="color: rgb(0,0,255)">var</span> query = <span
        style="color: rgb(43,145,175)">Product</span>.GetProducts().OrderBy(p =&gt; p.Name).Take(10);
            <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text = <span style="color: rgb(163,21,21)">"&lt;strong&gt;Ascending Order&lt;/strong&gt;&lt;br /&gt;\n"</span>;
            <span style="color: rgb(0,0,255)">foreach</span> (<span style="color: rgb(43,145,175)">Product</span> p <span
                style="color: rgb(0,0,255)">in</span> query)
                <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text += p.Name + <span
                    style="color: rgb(163,21,21)">"&lt;br /&gt;\n"</span>;

            <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text += <span
                style="color: rgb(163,21,21)">"&lt;br /&gt;\n"</span>;

            query = <span style="color: rgb(43,145,175)">Product</span>.GetProducts().OrderByDescending(p =&gt; p.Name).Take(10);
            <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text += <span
                style="color: rgb(163,21,21)">"&lt;strong&gt;Descending Order&lt;/strong&gt;&lt;br /&gt;\n"</span>;
            <span style="color: rgb(0,0,255)">foreach</span> (<span style="color: rgb(43,145,175)">Product</span> p <span
                style="color: rgb(0,0,255)">in</span> query)
                <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text += p.Name + <span
                    style="color: rgb(163,21,21)">"&lt;br /&gt;\n"</span>;</pre>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="ImperativeResultsZone" runat="server">
    <asp:Literal ID="litImperativeResults" runat="server" />
</asp:Content>
